<?php 

Class formsModel extends appModel
{
	function get_form($form_id)
	{
		$sql=" SELECT fields,name FROM ".$this->table('forms')." WHERE id= '".$form_id."'";
		$form=$this->getRow($sql);
		$temp=explode('::',$form['fields']);
		foreach($temp as $k=>$v)
		{
			$fields=json_decode($v);
			$fields_id=$fields->k;
			$sql=" SELECT name,type,field,default_val,data,tips FROM ".$this->table('fields')." WHERE id='".$fields_id."'";
			$form=$this->getRow($sql);
		}
	}
	
	function check_ip($opt)
	{
		$sql=" SELECT created FROM ".$this->table($opt['table'])." WHERE ip= '".$opt['ip']."' ORDER BY created DESC";
		$time=$this->getOne($sql);
		$dif=$_SERVER['REQUEST_TIME']-$time;
	
		if($time)
		{
			if($_SERVER['REQUEST_TIME']-$time<3600)
			{	
				return false;
			}
			else 
			{
				return true;
			}
			
		}
		else
		{
			return true;
		}
	}
	
	
}